local M = require "packages/mamashengde/record/Made"

local gongming = fk.CreateSkill {
  name = "shine__gongming",
}

Fk:loadTranslationTable {
  ["shine__gongming"] = "共鸣",
  [":shine__gongming"] = "当你消耗1点魔力后或失去1点体力后，你可以令称号与你相同的角色各摸X张牌（X为你本次变身此技能发动的次数）。",
}

gongming:addEffect(fk.HpLost, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(gongming.name)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local n = player:usedSkillTimes(gongming.name, Player.HistoryGame)
    local tos = {}
    for _, p in ipairs(room.alive_players) do
      if M.getHonor(p) == M.getHonor(player) then
        table.insert(tos, p)
      end
    end
    if #tos > 0 then
      for _, to in ipairs(tos) do
        to:drawCards(n, gongming.name)
      end
    end
  end,
})

gongming:addEffect(M.MaryokuConsumed, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return data and data.who == player and player:hasSkill(gongming.name)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local n = player:usedSkillTimes(gongming.name, Player.HistoryGame)
    local tos = {}
    for _, p in ipairs(room.alive_players) do
      if M.getHonor(p) == M.getHonor(player) then
        table.insert(tos, p)
      end
    end
    if #tos > 0 then
      for _, to in ipairs(tos) do
        to:drawCards(n, gongming.name)
      end
    end
  end,
})

return gongming